import React, { Component, PropTypes } from 'react';
import { Icon, Button, Table, Switch, Form, Input, Modal, Popconfirm } from 'antd';
import DynamicAddAnswer from './DynamicAddAnswer'




class QuestionGroupTable extends Component {

  constructor(props) {
    super(props)
    this.state = {
      visible: false,
      loading: false
    }
    this.columns = [{
      title: '问题列表',
      dataIndex: 'questions_name',
      key: 'questions_name'
    }, {
      title: '操作',
      dataIndex: '_id',
      key: 'action',
      render: (text,record) => <Popconfirm title="确认删除咩?" onConfirm={this.deleteOneQuestionHandler(record._id)}>
              <a href="#">Delete</a>
            </Popconfirm>
    }];

    this.deleteOneQuestionHandler = this.deleteOneQuestionHandler.bind(this)
    this.tableExpandedRowRender = this.tableExpandedRowRender.bind(this);
  }
  tableExpandedRowRender(record) {
    // console.log(record)

    return (
      <div className="room-userList" >
         <DynamicAddAnswer  question={record} updateOneQuestionById={this.props.updateOneQuestionById} />
        </div>
    )
  }
  onExpandedRowsChange(row){
    // console.log(row);
    // console.log(this.props,this)
  }
  deleteOneQuestionHandler(id) {
    // console.log(id)
    return () => {
      this.props.deleteOneQuestionById(id);
    }
  }
  render() {
    const { questionList, questionFetching } = this.props
    return (
      <Table
          loading={questionFetching}
          columns={this.columns}
          dataSource={questionList}
          className="table"
          expandedRowRender={(record)=>this.tableExpandedRowRender(record)}
          onExpandedRowsChange={this.onExpandedRowsChange.bind(this)}
        />

    )
  }
}



QuestionGroupTable = Form.create()(QuestionGroupTable);




export default QuestionGroupTable
